package forum.server.persistence.old;

import forum.server.domain.Admin;
import forum.server.domain.Gender;
import forum.server.domain.LoggedInUser;
import forum.server.domain.Moderator;
import java.util.Date;
public class UserTableEntry {
    /**
     * A unique username for each userification during login.,
     * used as ident
     */
    private String username;

    /**
     * A unique password for each user,
     * used as identification during login.
     */
    private String password;

    /**
     * User's personal information: first name, last name, gender, city name, birthday date.
     */
    private String firstName;
    private String lastName;
    private String email;
    private Gender gender;
    private String city;
    private Date birthday;
    private UserType type;
    /**
     * Constructor.
     */
    public UserTableEntry(){
        this.username="default";
        this.password="default";
        this.firstName="default";
        this.lastName="default";
        this.gender=Gender.UNSPECIFIED;
        this.city="default";
        this.birthday=new Date();
        this.type=UserType.LOGGEDINUSER;
    }
    /**
     * Constructor.
     * @param user the user to enter to the table.
     */
    public UserTableEntry(LoggedInUser user){
        this.username=user.getUsername();
        this.password=user.getPassword();
        this.firstName=user.getFirstName();
        this.lastName=user.getLastName();
        this.gender=user.getGender();
        this.city=user.getCity();
        this.birthday=user.getBirthday();
        if(user instanceof Admin)
            this.type=UserType.ADMIN;
        else{
            if(user instanceof Moderator)
                this.type=UserType.MODERATOR;
            else
                this.type=UserType.LOGGEDINUSER;
        }
    }

    /**
     * This function convers UserTableEntry to LoggedInUser.
     */
    public static LoggedInUser tableEntryToUser(UserTableEntry entry){
        UserType tType=entry.getType();
        switch (tType){
            case ADMIN:
                return new Admin(entry.getUsername(), entry.getPassword(),
                        entry.getFirstName(), entry.getLastName(), entry.getEmail(),
                        entry.getGender(), entry.getCity(), entry.getBirthday());
            case LOGGEDINUSER:
                return new LoggedInUser(entry.getUsername(), entry.getPassword(),
                        entry.getFirstName(), entry.getLastName(), entry.getEmail(),
                        entry.getGender(), entry.getCity(), entry.getBirthday());
            case MODERATOR:
                return new Moderator(entry.getUsername(), entry.getPassword(),
                        entry.getFirstName(), entry.getLastName(), entry.getEmail(),
                        entry.getGender(), entry.getCity(), entry.getBirthday());
            default:
                return null;
        }
    }
    private String getEmail() {
		return this.email;
	}
	/**
     * getter for the birthday field.
     * @return the birthday.
     */
    public Date getBirthday() {
        return this.birthday;
    }
    /**
     * getter for the city field.
     * @return the city.
     */
    public String getCity() {
        return this.city;
    }
    /**
     * getter for the firstName field.
     * @return the first name.
     */
    public String getFirstName() {
        return this.firstName;
    }
    /**
     * getter for the gender field.
     * @return the gender.
     */
    public Gender getGender() {
        return gender;
    }
    /**
     * getter for the lastName field.
     * @return the last name.
     */
    public String getLastName() {
        return this.lastName;
    }
    /**
     * getter for the password field.
     * @return the pass.
     */
    public String getPassword() {
        return this.password;
    }
    /**
     * getter for the type field.
     * @return the type- admin,Reguser,moderator.
     */
    public UserType getType() {
        return this.type;
    }
    /**
     * getter for the username field.
     * @return the username.
     */
    public String getUsername() {
        return this.username;
    }
    /**
     * setter for the birthday field.
     * @param birthday of the user.
     */
    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }
    /**
     * setter for the city field.
     * @param city the city of the user.
     */
    public void setCity(String city) {
        this.city = city;
    }
    /**
     * setter for the firstName field.
     * @param firstName the first name of the user.
     */
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }
    /**
     * setter for the gender field.
     * @param gender the gender of the user.
     */
    public void setGender(Gender gender) {
        this.gender = gender;
    }
    /**
     * setter for the lastName field.
     * @param lastName the last name of the user.
     */
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }
    /**
     * setter for the password field.
     * @param password the new password.
     */
    public void setPassword(String password) {
        this.password = password;
    }
    /**
     * setter for the type field.
     * @param type admin,moderator,reguser.
     */
    public void setType(UserType type) {
        this.type = type;
    }
    /**
     * setter for the username field.
     * @param username the new username.
     */
    public void setUsername(String username) {
        this.username = username;
    }

}
